package modeller.queueingnetworksmodel.structure;

import modeller.databasedesignmodel.relation.Relation;
import modeller.databasedesignmodel.servicedemand.IServiceDemand;
import modeller.databasedesignmodel.transaction.Transaction;
import modeller.queueingnetworksmodel.probabilities.TransactionRoutingMatrix;
import org.jdom2.Attribute;
import org.jdom2.Element;
import org.jdom2.Namespace;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;

/**
 * Created by:  Jason Ye
 * Date:        30/05/2012
 * Time:        20:50
 */
public class Archive implements IQueueingNetworkModelXMLNode {

    private String absoluteFileName;

    private Sim sim;
    private HashMap<Transaction, IServiceDemand> serviceDemands;

    public Archive(HashSet<Relation> relations, HashSet<Transaction> transactions, TransactionRoutingMatrix qnInstantaneousTransitionMatrix, Relation[] relationArray, String fileName, HashMap<Transaction, IServiceDemand> serviceDemands) {

        this.absoluteFileName = fileName;
        this.serviceDemands = serviceDemands;

        this.sim = new Sim(qnInstantaneousTransitionMatrix, transactions, relations, fileName, this.serviceDemands);
    }

    @Override
    public Element toXMLRepresentation() {

        Element result = new Element("archive");

        String pwd = new File(".").getAbsolutePath();
        //String fileName = absoluteFileName.substring(pwd.length(),absoluteFileName.length()-1);
        System.out.println(absoluteFileName);
        result.setAttribute("name", absoluteFileName);
        Date date = new Date();
        // format timestamp with year:month:day-hour:minute:sec
        SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd kk:mm:ss G yyyy");
        String formattedDate = sdf.format(date);
        result.setAttribute("timestamp",formattedDate);

        // / result.setAttribute("timestamp");
        result.setAttribute(new Attribute("noNamespaceSchemaLocation", "Archive.xsd", Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")));

        result.addContent(sim.toXMLRepresentation());

        return result;
    }
}
